package com.melodyframe.common.context.loader;

import com.melodyframe.common.tools.bean.PropertyEntry;

public class ContextRequest<T> {
	private String		name;
	private String		scope;
	private String		format;
	private Class<T>	classType;

	public static <C> ContextRequest<C> forRequest(Class<C> classType) {
		ContextRequest<C> request = new ContextRequest<C>();
		request.setClassType(classType);
		return request;
	}

	public static <C> ContextRequest<C> forRequest(String name,
			Class<C> classType) {
		ContextRequest<C> request = forRequest(classType);
		request.setName(name);
		return request;
	}

	public ContextRequest<T> root(String root) {
		if (null != root) {
			this.setName(root + "." + this.getName());
		}
		return this;
	}

	public ContextRequest<T> scope(String scope) {
		this.setScope(scope);
		return this;
	}

	public ContextRequest<T> format(String format) {
		this.setFormat(format);
		return this;
	}

	public <C> ContextRequest<C> property(PropertyEntry<C> property) {
		ContextRequest<C> request = new ContextRequest<C>();
		request.setClassType(property.getType());
		request.setScope(this.getScope());
		request.setName(null == this.getName() ? property.getName() : this
				.getName() + "." + property.getName());
		return request;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getScope() {
		return scope;
	}

	public void setScope(String scope) {
		this.scope = scope;
	}

	public String getFormat() {
		return format;
	}

	public void setFormat(String format) {
		this.format = format;
	}

	public Class<T> getClassType() {
		return classType;
	}

	public void setClassType(Class<T> classType) {
		this.classType = classType;
	}

	public enum ParameterType {
		ATTRIBUTE, MODEL
	}

}
